{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 对活动进行聚类\n",
    "\n",
    "数据来源于Kaggle竞赛：Event Recommendation Engine Challenge，根据\n",
    "events they’ve responded to in the past\n",
    "user demographic information\n",
    "what events they’ve seen and clicked on in our app\n",
    "用户对某个事件是否感兴趣\n",
    "\n",
    "竞赛官网：\n",
    "https://www.kaggle.com/c/event-recommendation-engine-challenge/data\n",
    "\n",
    "活动描述信息在events.csv文件：共110维特征\n",
    "前9列：event_id, user_id, start_time, city, state, zip, country, lat, and lng.\n",
    "event_id：活动的id, \n",
    "user_id：创建活动的用户的id .  \n",
    "city, state, zip, and country： 活动地点 (如果知道的话).\n",
    "lat and lng： floats（活动地点的经度和纬度）\n",
    "start_time： 字符串，ISO-8601 UTC time，表示活动开始时间\n",
    "\n",
    "后101列为词频：count_1, count_2, ..., count_100，count_other\n",
    "count_N：活动描述出现第N个词的次数\n",
    "count_other：除了最常用的100个词之外的其余词出现的次数\n",
    "\n",
    "作业要求：\n",
    "根据活动的关键词（count_1, count_2, ..., count_100，count_other属性）做聚类，可采用KMeans聚类\n",
    "尝试K=10，20，30，..., 100, 并计算各自CH_scores。\n",
    "\n",
    "提示：由于样本数目较多，建议使用MiniBatchKMeans。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from __future__ import print_function\n",
    "from __future__ import division\n",
    "\n",
    "## 导入工具包\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "#特征编码\n",
    "from utils import FeatureEng\n",
    "\n",
    "from sklearn.preprocessing import normalize\n",
    "from sklearn import metrics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#读取数据\n",
    "import scipy.io as sio\n",
    "eventContMatrix = sio.mmread(\"EV_eventContMatrix\") "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from sklearn.cluster import MiniBatchKMeans\n",
    "\n",
    "# 一个参数点（聚类数据为K）的模型，并评价聚类算法性能\n",
    "def K_cluster_analysis(K, df):\n",
    "    print(\"K-means begin with clusters: {}\".format(K));\n",
    "    \n",
    "    #K-means,在训练集上训练\n",
    "    km = MiniBatchKMeans(n_clusters = K)\n",
    "    km.fit(df)\n",
    "    \n",
    "    #保存预测结果\n",
    "    cluster_result = km.predict(df)\n",
    "\n",
    "    # K值的评估标准\n",
    "    #常见的方法有轮廓系数Silhouette Coefficient和Calinski-Harabasz Index\n",
    "    #这两个分数值越大则聚类效果越好\n",
    "    #CH_score = metrics.calinski_harabaz_score(X_train,mb_kmeans.predict(X_train))\n",
    "    CH_score = metrics.silhouette_score(df,cluster_result)   \n",
    "    print(\"CH_score: {}\".format(CH_score))\n",
    "\n",
    "    return CH_score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "K-means begin with clusters: 10\n",
      "CH_score: 0.09191419852895243\n",
      "K-means begin with clusters: 20\n",
      "CH_score: 0.02333119502666583\n",
      "K-means begin with clusters: 30\n",
      "CH_score: -0.06454746753892404\n",
      "K-means begin with clusters: 40\n",
      "CH_score: -0.062191152652989065\n",
      "K-means begin with clusters: 50\n",
      "CH_score: -0.024135366329845552\n",
      "K-means begin with clusters: 60\n",
      "CH_score: -0.0759430693791694\n",
      "K-means begin with clusters: 70\n",
      "CH_score: -0.14719290305473934\n",
      "K-means begin with clusters: 80\n",
      "CH_score: -0.1203596408938\n",
      "K-means begin with clusters: 90\n",
      "CH_score: -0.04693071567437062\n",
      "K-means begin with clusters: 100\n",
      "CH_score: -0.12782111415236574\n"
     ]
    }
   ],
   "source": [
    "# 设置超参数（聚类数目K）搜索范围\n",
    "CH_scores = []\n",
    "Ks = [10,20,30,40,50,60,70,80,90,100]\n",
    "for K in Ks:\n",
    "    ch = K_cluster_analysis(K, eventContMatrix)\n",
    "    CH_scores.append(ch)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0.091914198528952426, 0.023331195026665828, -0.064547467538924042, -0.062191152652989065, -0.024135366329845552, -0.075943069379169406, -0.14719290305473934, -0.1203596408938, -0.04693071567437062, -0.12782111415236574]\n"
     ]
    }
   ],
   "source": [
    "print(CH_scores)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x299c5860748>]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYYAAAD8CAYAAABzTgP2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xec1NX1//HXodkAFUECoqIGC7GgrDWKHbEFNEaxJBg1\nyE9QQRcWUQQUCSKIGFFjx0rURDB2URNboiwWRAy6CCiIgBIhWGh7f3+c4esu7sLuTrlT3s/HYx67\nM/P5zOfMB3bO3Pu59x4LISAiIrJOvdgBiIhIdlFiEBGRSpQYRESkEiUGERGpRIlBREQqUWIQEZFK\nlBhERKQSJQYREalEiUFERCppkIoXMbMuwDigPnBXCGHkes/vDtwL7AdcGUIYXdN9q9K8efPQtm3b\nVIQuIlIwpk2b9lUIocXGtks6MZhZfWA8cCwwH5hqZk+GEGZW2GwpcAnQrQ77/kTbtm0pLS1NNnQR\nkYJiZvNqsl0qupIOAMpCCJ+GEFYBE4GuFTcIISwOIUwFVtd2XxERyaxUJIbtgM8r3J+feCzd+4qI\nSBrkzMVnM+tpZqVmVrpkyZLY4YiI5K1UJIYFwPYV7rdJPJbSfUMId4QQikIIRS1abPTaiYiI1FEq\nEsNUoJ2Z7WRmjYDuwJM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/GNgE+B3+Nf2grufJjZMOAMfDTfu8AF\nQGMK5Fwkql0ega+guggYAkyimvdvZlcC5+Hnq28I4dmUxKHEICIiFakrSUREKlFiEBGRSpQYRESk\nEiUGERGpRIlBREQqUWIQEZFKlBhERKQSJQYREank/wMbNJ1LVDHX2wAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x299c003f9b0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 绘制不同聚类数目的模型的性能，找到最佳模型／参数（分数最高）\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "\n",
    "plt.plot(Ks, np.array(CH_scores), 'b-')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "celltoolbar": "Raw Cell Format",
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
